import { defineStore } from 'pinia'
import { getHotSuggests, getHomeCategories, getHouselistData } from '@/services'

const useHomeStore = defineStore('home', {
	state: () => ({
		hotSuggests: [],
		categories: [],
		houselist: [],

		currentPage: 1,
	}),
	actions: {
		async fetchHotSuggestDate() {
			const res = await getHotSuggests()
			this.hotSuggests = res.data
		},
		async fetchCategoriesData() {
			const res = await getHomeCategories()
			this.categories = res.data
		},
		async fetchHouselistData() {
			const res = await getHouselistData(this.currentPage)
			this.houselist = [...this.houselist, ...res.data]
			this.currentPage++
		},
	},
})

export default useHomeStore
